import Vue from "vue";

import Index from "./Index.vue";
import router from "./router";
import ElementUi from "element-ui";
import { Tree } from "@femessage/element-ui";
import VueParticles from "vue-particles";
import AppConf from "@/config";
import store from "@/store/store";
import "font-awesome/css/font-awesome.min.css";
import util from "@/libs/";
import "@/config/axiosConfig";
import * as filters from "@/filters";
import Router from "vue-router";
import component from "@/components";
import echarts from "echarts";
import vuescroll from "vuescroll";
import "vuescroll/dist/vuescroll.css";
import VueContextMenu from "vue-contextmenu";
import "@/assets/icon/iconfont.css";
import "element-ui/lib/theme-chalk/index.css";
import VueDragResize from "vue-drag-resize"; //缩放、拖拽
import base from "@/libs/base";
import dataV from '@jiaminghi/data-view'

import BaiduMap from 'vue-baidu-map'

Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: 'CpOG4yhxYwhA5GRmcqRLn9KUhKGGCdG9'
})

Vue.use(dataV)
base.setIco();
base.addDDLogin();
Vue.component("vue-drag-resize", VueDragResize);
Vue.component("femessage-tree", Tree);
Vue.use(VueContextMenu);
Vue.use(vuescroll);
//复制到粘贴板插件
import VueClipboard from "vue-clipboard2";

VueClipboard.config.autoSetContainer = true;
Vue.use(VueClipboard);
Vue.prototype.$echarts = echarts;
Vue.use(AppConf);
Vue.use(require("vue-wechat-title"));
Vue.use(ElementUi);
Vue.use(VueParticles);
Vue.use(util);
Vue.use(component);

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};
// 导入过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});

/** 权限指令**/
Vue.directive("has", {
  inserted: function(el, binding) {
    const className = binding.value.class; // 这个地方要注意了，看下面页面上的代码，对应取得相应的值

    if (!Vue.prototype.$_has(className)) {
      el.parentNode.removeChild(el);
    }
  }
});

/** 路由拼接token验证  **/
router.beforeEach((to, from, next) => {
  if (!window.sessionStorage.getItem("token")) {
    if (to.query.token) {
      window.sessionStorage.setItem("token", to?.query?.token);
    }
    next();
  } else {
    next();
  }
});
Vue.prototype.$bus = new Vue()
Vue.prototype.$_has = function(val) {
  let isShow = false;
  const btnPowerArr = sessionStorage.getItem("roleKeys");
  if (btnPowerArr === undefined || btnPowerArr === null || btnPowerArr === "") {
    return false;
  }
  if (btnPowerArr.indexOf(val) > -1) {
    isShow = true;
  }
  return isShow;
};

function init() {
  if (!window.api.domain) {
    setTimeout(() => {
      init();
    }, 250);
    return;
  }
  new Vue({
    router,
    store,
    render: h => h(Index)
  }).$mount("#app");
}

init();